#!/bin/bash

# Quick start script for Ignite Fun Backend
echo "🚀 Starting Ignite Fun Backend..."

# Navigate to backend directory
cd "$(dirname "$0")"

# Check if we're in the right directory
if [ ! -f "package.json" ]; then
    echo "❌ Error: package.json not found. Please run this script from the backend directory."
    exit 1
fi

# Check database connection
echo "🗄️ Checking database connection..."
if ! npx prisma db pull --force --schema=prisma/schema.prisma > /dev/null 2>&1; then
    echo "⚠️ Database connection failed. Make sure PostgreSQL is running on localhost:5432"
    echo "💡 You can start the database with: docker-compose -f ../docker-compose.yml up -d postgres redis"
fi

# Generate Prisma client
echo "🔄 Generating Prisma client..."
pnpm prisma generate

# Start development server
echo "🚀 Starting development server on http://localhost:8080"
echo "📚 API Documentation: http://localhost:8080/api/docs"
echo "🔌 WebSocket: ws://localhost:8080/realtime"
echo ""

pnpm start:dev
